package com.jeespring.storage.service.impl;

import com.jeespring.dto.ResponseDTO;
import com.jeespring.entity.Storage;
import com.jeespring.service.StorageService;
import com.jeespring.storage.dao.StorageDao;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Title: StorageServiceImpl
 * @Description:
 * @Author 张朝阳
 * @Date 2020/11/29 14:06
 */
@Service
public class StorageServiceImpl implements StorageService {

    @Autowired
    private StorageDao storageDao;

    @Override
    public List<Storage> query(Storage storage) {
        return storageDao.select(storage);
    }

    @Override
    public ResponseDTO decrStorage(Storage storage) {
        ResponseDTO<Object> response = new ResponseDTO<>();
        int count = storageDao.decrStorage(storage.getCommodityCode(), storage.getCount());
        if (count > 0){
            response.setSuccess(true);
            response.setMessage("扣减库存成功！");
            return response;
        }

        response.setSuccess(false);
        response.setMessage("扣减库存失败！");
        return response;
    }
}
